const { defineConfig } = require("@vue/cli-service");
const path = require("path");
function resolve(dir) {
  return path.join(__dirname, ".", dir);
}
const packageName = "monitor";
const url =
  process.env.VUE_APP_ENV === "development"
    ? process.env.VUE_APP__MONITOR_API
    : `/${packageName}`;
module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave: false,
  publicPath: url,
  outputDir: packageName,
  devServer: {
    open: true,
    port: 10018,
    headers: {
      "Access-Control-Allow-Origin": "*",
    },
    client: {
      overlay: false,
    },
    historyApiFallback: {
      index: "/index.html",
    },
    // proxy: {
    //   '/api/monitor': {
    //     // target: 'http://10.176.118.58:8100',
    //     target: 'http://10.189.111.130/api/monitor',
    //     pathRewrite: { '^/api/monitor': '' },
    //     changeOrigin: true
    //   },
    //   '/api/monitor/dev': {
    //     // target: 'http://10.189.111.130/api/monitor/dev',
    //     target: 'http://10.176.64.37:5000/',
    //     pathRewrite: { '^/api/monitor/dev': '' },
    //     changeOrigin: true
    //   }
    // }
    proxy: {
      "/apmServer-sl": {
        target: "http://10.10.103.35:39391",
        target: "http://10.10.103.35:39191",
        // target: 'http://10.10.114.105:9191',
        // target: 'http://10.10.114.109:9191',
        changeOrigin: true,
      },
    },
  },
  configureWebpack: {
    resolve: {
      alias: {
        "@": resolve("src"),
      },
    },
    output: {
      library: `${packageName}-[name]`,
      libraryTarget: "umd", // 把微应用打包成 umd 库格式
      chunkLoadingGlobal: `webpackJsonp_${packageName}`,
    },
  },
  chainWebpack(config) {
    // config.plugins.delete('preload') // TODO: need test
    // config.plugins.delete('prefetch') // TODO: need test
    // config.module.rules.delete("svg");
    config.module
      .rule("yaml")
      .test(/\.ya?ml$/)
      .use("yaml")
      .loader("js-yaml-loader");
    // set svg-sprite-loader
    config.module.rule("svg").exclude.add(resolve("src/icons")).end();
    config.module
      .rule("icons")
      .test(/\.svg$/)
      .include.add(resolve("src/icons"))
      .end()
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      .options({
        symbolId: "icon-[name]",
      })
      .end();
    config.module
      .rule("vue")
      .use("vue-loader")
      .loader("vue-loader")
      .tap((options) => {
        options.compilerOptions = { preserveWhitespace: true };
        return options;
      })
      .end();
  },
});
